package com.bpc.cs.dao;

import com.bpc.cs.dto.FactorChoiceDTO;

/**
 * @author   phan_tp
 * @datetime Dec 18, 2012 : 9:27:10 AM
 */
public class FactorChoiceDAO extends BaseDAO implements IFactorChoiceDAO {

	/**
	 * Insert new factor choice
	 * @param FactorChoice factorChoiceDTO
	 * @return boolean TRUE : insert successfully
	 * 				   FALSE: insert failed
	 */
	@Override
	public boolean insertFactorChoice(FactorChoiceDTO factorChoiceDTO) {
		getSession().save(factorChoiceDTO);
		return true;
	}

	/**
	 * Delete factor choice
	 * @param int factorChoiceID
	 * @return boolean TRUE : Delete successfully
	 * 				   FALSE: Delete failed
	 */
	@Override
	public boolean deleteFactorChoice(int factorChoiceID) {
		int numEffRow = getSession().createQuery("DELETE FROM FactorChoiceDTO WHERE factorChoiceID = ?")
									.setParameter(0, factorChoiceID)
									.executeUpdate();
		return numEffRow == 1;
	}

	/**
	 * Count the number of ruleID in table SCORING_FACTOR_CHOICE
	 * @param int ruleID
	 * @return the number of ruleID
	 */
	public int countRuleID(int ruleID) {
		return ((Number)getSession().createQuery("SELECT COUNT(*) FROM FactorChoiceDTO WHERE ruleDTO.ruleID = ?")
									.setParameter(0, ruleID)
									.uniqueResult())
									.intValue();
	}
}
